<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('查看文书')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <!--<div class="btn-group-sm" id="toolbar" role="group">-->
        <!--<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="publish:register:add">-->
            <!--<i class="fa fa-plus"></i> 添加文书-->
        <!--</a>-->
    <!--</div>-->
    <form class="form-horizontal m" id="form-paperwork-detail" th:object="${idAcceptRegister}">
        <input name="id" th:field="*{id}" type="hidden">


        <h4 class="form-header h4">来函</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">来函文件：</label>
                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="acceptFiles" th:field="*{acceptFiles}" style="visibility: hidden;" >
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" id="acceptFiles" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">回函</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">出版意见：</label>
                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="publishOps" th:value="${publishOps}" style="visibility: hidden;" >
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" id="publishOps" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">鉴定登记表</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">终版-鉴定登记表：</label>
                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="finalRegister" th:field="*{finalRegister}" style="visibility: hidden;" >
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" id="finalRegister" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">签发单</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">终版-签发单：</label>
                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="finalIssue" th:field="*{finalIssue}" style="visibility: hidden;" >
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" id="finalIssue" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="form-header h4">送达登记表</h4>
        <div class="row">
            <div class="col-md-12">
                <div class="form-group">
                    <label class="col-sm-2 control-label ">终版-送达登记表：</label>
                    <div class="col-sm-10">
                        <!--             type="hidden"  class="myhide"          width设置为0，高度设置为0.5px-->
                        <input name="finalDeliver" th:field="*{finalDeliver}" style="visibility: hidden;" >
                        <br/>
                        <div class="file-loading">
                            <input class="form-control file-upload" id="finalDeliver" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script src="/ajax/libs/template/template.js"></script>
<script th:inline="javascript">
    var prefix = ctx + "publish/paperwork";

    $("#form-report-add").validate({
        focusCleanup: true
    });


    var handle = null;
    $(document).ready(function () {
        handle = setInterval(function () {
            fileAfterInitial();

            $('input.form-control').attr('readonly', true);
            $('textarea.form-control').attr('readonly', true);
            $('.file-caption-main').remove();
            $('input[name="publishingTime"]').attr("disabled", true);
            $('.btn-file').remove();
            $('#appraCon').attr('readonly', true).attr('disabled', true);
            $('#sendUnitId').attr('disabled', true);
            $('button.close').remove();
            $('.file-actions button[title="删除文件"]').remove();
            if ($('input.form-control').attr('readonly')) {
                clearInterval(handle);
            }
        }, 800);


        $('.summernote').summernote({
            lang: 'zh-CN',
            callbacks: {
                onChange: function (contents, $edittable) {
                    $("input[name='" + this.id + "']").val(contents);
                },
                onImageUpload: function (files) {
                    var obj = this;
                    var data = new FormData();
                    data.append("file", files[0]);
                    $.ajax({
                        type: "post",
                        url: ctx + "common/upload",
                        data: data,
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $('#' + obj.id).summernote('insertImage', result.url);
                            } else {
                                $.modal.alertError(result.msg);
                            }
                        },
                        error: function (error) {
                            $.modal.alertWarning("图片上传失败。");
                        }
                    });
                }
            }
        });
    });


    var sca = function (event) {
        $("input[name='" + event.currentTarget.id + "']").val("");
        sca = function () {
        }
    }

    // 上传
    $(".file-upload").each(function (i) {
        var vals = new Array()
        var preList = new Array();
        if ($.common.isNotEmpty($("input[name='" + this.id + "']").val())) {
            var str = $("input[name='" + this.id + "']").val();
            var strs = new Array();
            strs = str.split(",");
            for (i = 0; i < strs.length; i++) {
                vals[i] = ctx.slice(0, ctx.length - 1) + strs[i];
            }

        }
        var previewJson = preList;
        var preConfigList = new Array();
        for (var i = 0; i < vals.length; i++) {
            var array_element = vals[i];
            var name = vals[i].substring(vals[i].lastIndexOf("/") + 1);
            var tjson = {
                caption: name, // 展示的文件名
                width: '100px',
                alt: array_element,
                extra: {id: 100}
            };
            preConfigList[i] = tjson;
        }
        $(this).fileinput({
            uploadUrl: '/common/upload',
            initialPreviewAsData: true,
            initialPreview: vals,
            maxFileCount: 0,
            showUpload: false,
            showRemove: true,
            maxFileSize: 30000,
            autoReplace: true,
            //allowedFileExtensions: ['jpg', 'png', 'bmp', 'jpeg'],
            showUpload: false, //是否显示上传按钮
            showCaption: true,//是否显示标题
            browseClass: "btn btn-primary hide",//按钮样式
            dropZoneTitle: " ",
            otherActionButtons: '<button type="button" class="kv-file-down btn btn-sm btn-default" {dataKey} title="下载附件"><i class="fa fa-cloud-download"></i></button>',
            layoutTemplates: {
                actionDelete: '', //去除上传预览的缩略图中的删除图标
                actionUpload: '',//去除上传预览缩略图中的上传图片图标；
                //     actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
            },
            previewFileIcon: '<i class="fa fa-file-o text-info"></i>',
            preferIconicPreview: true,// 是否优先显示图标  false 即优先显示图片
            previewFileIconSettings: {
                'docx': '<i class="fa fa-file-word-o text-primary"></i>',
                'doc': '<i class="fa fa-file-word-o text-primary"></i>',
                'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
                'xls': '<i class="fa fa-file-excel-o text-success"></i>',
                'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'ppt': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
                'pdf': '<i class="fa fa-file-pdf-o text-danger"></i>',
                'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
                'sql': '<i class="fa fa-file-word-o text-primary"></i>',
                'txt': '<i class="fa fa-file-text-o text-info"></i>',
                'rtf': '<i class="fa fa-file-text-o text-info"></i>',
            },
            initialPreviewConfig: preConfigList
        }).on('filebatchselected', function (event, data, id, index) {
            $(this).fileinput("upload");
        }).on('fileuploaded', function (event, data, previewId, index) {
            //若重新上传文件，清空当前文件路径,只执行一次清空函数
            sca(event);
            if ($("input[name='" + event.currentTarget.id + "']").val() == "") {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName);
            } else {
                $("input[name='" + event.currentTarget.id + "']").val($("input[name='" + event.currentTarget.id + "']").val() + ',' + data.response.fileName);
            }
        }).on('filecleared', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on('filesuccessremove', function (event, id, index) {
            var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
            fileUrlList.splice(index, 1);
            $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
        }).on('filedeleted', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        }).on('filepreremove', function (event, id, index) {
            var str_after = index.split('_')[1];
            var fileUrlList = $("input[name='" + event.currentTarget.id + "']").val().split(",");
            fileUrlList.splice(str_after, 1);
            $("input[name='" + event.currentTarget.id + "']").val(fileUrlList);
        });
        // $(this).fileinput('_initFileActions');
    });

    $(document).ready(function () {
        var fileConfig={
            uploadUrl: '/common/upload',
            maxFileSize:30000,
            browseClass:'btn btn-primary',
            dropZoneTitle:" ",
        }
        $.common.uploadFileInput(fileConfig,".file-upload","input[name='acceptFiles']");

    });


    /**
     * 其他按钮（如下载）绑定时间
     */
    $(document).on('click', '.kv-file-down', function (e, id, index) {
        var download = "";
        // 获取父级DIV
        var fileIndex = $(this).parents(".file-preview-frame").attr("data-fileindex");

        var fileValue = $(this).parents(".col-sm-10").children("input").val();
        if (fileIndex) {
            var number = fileIndex.match(/\d/);
            if (number) {
                download = fileValue.split(",")[number];
            }
        }
        var name = download.substring(download.lastIndexOf("/") + 1);
        if (download != "") {
            downloadFile(download, name);
        }
    });

    function downloadFile(url, name) {
        var a = document.createElement("a");
        a.download = name;
        a.href = url;
        $("body").append(a); // 修复firefox中无法触发click
        a.click();
        $(a).remove();
    };



    // 刷新 iframe
    function reloadAllIframe() {
        var iframe = window.parent.document.querySelectorAll('iframe');
        for (var i = 0, end = iframe.length; i < end; i++) {
            if (iframe[i].getAttribute("data-id") == "/publish/report") {
                iframe[i].contentWindow.location.reload();
                break;
            }
        }
    }

    function fileAfterInitial() {
        var fileConfig={
            uploadUrl: '/common/upload',
            maxFileSize:30000,
            browseClass:'btn btn-primary',
            dropZoneTitle:"拖拽文件到这里",
        }
        $.common.uploadFileInput(fileConfig,".file-uploadAfter","input[name='copyrightRecord']");
    }

</script>
</body>

</html>

